#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#include <api/libtsi/sec_pmt.h>
#ifndef NEW_DEMO_FRAME
#include <api/libpub29/lib_pub27.h>
#include <api/libpub29/lib_hde.h>
#else
#include <api/libpub/lib_hde.h>
#include <api/libpub/lib_pub.h>
#endif
#include <hld/dis/vpo.h>

//#include <api/libdb/db_config.h>
#include <api/libdb/db_return_value.h>
#ifndef COMBOUI
#include <api/libdb/db_node_s.h>
#else
#include <api/libdb/db_node_combo.h>
#endif
#include <api/libdb/db_node_api.h>
#include <api/libdb/db_interface.h>

#include <api/libosd/osd_lib.h>

#include "osdobjs_def.h"
#include "string.id"
#include "images.id"
#include "osd_config.h"

#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_signalstatus.h"

#define LCLST_PRINTF soc_printf

#define LCL_TEST				/* Testing */
#define PLAY_CH_AFTER_CHGRP	/* Play channel after change group */

/*******************************************************************************
*	Objects definition
*******************************************************************************/
#define LIST_CNT	10

#define VACT_GROUP_DECREASE	(VACT_PASS + 1)
#define VACT_GROUP_INCREASE	(VACT_PASS + 2)
#define VACT_GROUP_ALL_SELECT	(VACT_PASS + 3)
#define VACT_GROUP_FAV_SELECT	(VACT_PASS + 4)
#define VACT_PLAY_CH			(VACT_PASS + 5)
#define VACT_TV_RADIO_SW		(VACT_PASS + 6)

extern CONTAINER    g_win_light_chanlist;

extern TEXT_FIELD	lcl_title;
extern TEXT_FIELD	lcl_info;
extern OBJLIST	  	lcl_item_list;
extern SCROLL_BAR	lcl_list_bar;

extern CONTAINER    lcl_item_con1;
extern CONTAINER    lcl_item_con2;
extern CONTAINER    lcl_item_con3;
extern CONTAINER    lcl_item_con4;
extern CONTAINER    lcl_item_con5;
extern CONTAINER    lcl_item_con6;
extern CONTAINER    lcl_item_con7;
extern CONTAINER    lcl_item_con8;
extern CONTAINER    lcl_item_con9;
extern CONTAINER    lcl_item_con10;
extern CONTAINER    lcl_item_con11;

extern BITMAP    	lcl_item_bmp1;
extern BITMAP    	lcl_item_bmp2;
extern BITMAP    	lcl_item_bmp3;
extern BITMAP    	lcl_item_bmp4;
extern BITMAP    	lcl_item_bmp5;
extern BITMAP    	lcl_item_bmp6;
extern BITMAP    	lcl_item_bmp7;
extern BITMAP    	lcl_item_bmp8;
extern BITMAP    	lcl_item_bmp9;
extern BITMAP    	lcl_item_bmp10;
extern BITMAP    	lcl_item_bmp11;

extern TEXT_FIELD 	 lcl_item_txtidx1;
extern TEXT_FIELD    lcl_item_txtidx2;
extern TEXT_FIELD    lcl_item_txtidx3;
extern TEXT_FIELD    lcl_item_txtidx4;
extern TEXT_FIELD    lcl_item_txtidx5;
extern TEXT_FIELD    lcl_item_txtidx6;
extern TEXT_FIELD    lcl_item_txtidx7;
extern TEXT_FIELD    lcl_item_txtidx8;
extern TEXT_FIELD    lcl_item_txtidx9;
extern TEXT_FIELD    lcl_item_txtidx10;
extern TEXT_FIELD    lcl_item_txtidx11;

extern TEXT_FIELD    lcl_item_txtnam1;
extern TEXT_FIELD    lcl_item_txtnam2;
extern TEXT_FIELD    lcl_item_txtnam3;
extern TEXT_FIELD    lcl_item_txtnam4;
extern TEXT_FIELD    lcl_item_txtnam5;
extern TEXT_FIELD    lcl_item_txtnam6;
extern TEXT_FIELD    lcl_item_txtnam7;
extern TEXT_FIELD    lcl_item_txtnam8;
extern TEXT_FIELD    lcl_item_txtnam9;
extern TEXT_FIELD    lcl_item_txtnam10;
extern TEXT_FIELD    lcl_item_txtnam11;



static VACTION lcl_item_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT lcl_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION lcl_item_lst_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT lcl_item_lst_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION lcl_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT lcl_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

/*
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
#define WIN_SH_IDX	  WSTL_WIN_SLIST_02_8BIT
#else
#define WIN_SH_IDX	  WSTL_WIN_SLIST_01_8BIT //WSTL_WIN_SLIST_01
#endif
*/
#if Maker_GUI_ON
#define WIN_SH_IDX	 WSTL_WIN_SLIST_02_8BIT 
#define TITLE_SH_IDX	WSTL_WIN_TITLE_YJ
#else
#define WIN_SH_IDX	  WSTL_WIN_SLIST_02_8BIT
#define TITLE_SH_IDX	WSTL_TEXT_16_8BIT //WSTL_TEXT_16
#endif



#define WIN_HL_IDX	  WIN_SH_IDX //WSTL_WIN_SLIST_01
#define WIN_SL_IDX	  WIN_SH_IDX //WSTL_WIN_SLIST_01
#define WIN_GRY_IDX   WIN_SH_IDX //WSTL_WIN_SLIST_01
 
#define INFO_SH_IDX	    WSTL_TEXT_01_8BIT //WSTL_TEXT_15_8BIT//WSTL_TEXT_15

#define LIST_SH_IDX		WSTL_NOSHOW_IDX
#define LIST_HL_IDX		WSTL_NOSHOW_IDX
#define LIST_SL_IDX		WSTL_NOSHOW_IDX
#define LIST_GRY_IDX	WSTL_NOSHOW_IDX

#define LIST_BAR_SH_IDX  WSTL_SCROLLBAR_01_8BIT//WSTL_SCROLLBAR_01
#define LIST_BAR_HL_IDX  WSTL_SCROLLBAR_01_8BIT//WSTL_SCROLLBAR_01

#define LIST_BAR_MID_RECT_IDX  	WSTL_NOSHOW_IDX
#define LIST_BAR_MID_THUMB_IDX  	WSTL_SCROLLBAR_02_8BIT//WSTL_SCROLLBAR_02

#define CON_SH_IDX   WSTL_TEXT_15_8BIT //WSTL_TEXT_01_8BIT //WSTL_TEXT_12
#define CON_HL_IDX   WSTL_BUTTON_05_8BIT //WSTL_BUTTON_05//WSTL_BUTTON_02
#define CON_SL_IDX   WSTL_TEXT_15_8BIT //WSTL_TEXT_01_8BIT //WSTL_TEXT_12
#define CON_GRY_IDX  WSTL_TEXT_14

#define BMP_SH_IDX   WSTL_LINE_MENU_HD//sharon WSTL_MAINMENU_LINE_8BIT 
#define BMP_HL_IDX   BMP_SH_IDX//WSTL_MIXBACK_BLACK_IDX
#define BMP_SL_IDX   BMP_SH_IDX//WSTL_MIXBACK_BLACK_IDX
#define BMP_GRY_IDX  BMP_SH_IDX//WSTL_MIXBACK_BLACK_IDX

#define TXTI_SH_IDX   WSTL_TEXT_15_8BIT//WSTL_TEXT_28_8BIT //WSTL_TEXT_13
#define TXTI_HL_IDX   WSTL_TEXT_28_8BIT//WSTL_BUTTON_02_FG
#define TXTI_SL_IDX   WSTL_TEXT_15_8BIT//WSTL_TEXT_28_8BIT //WSTL_TEXT_13
#define TXTI_GRY_IDX  WSTL_TEXT_14

#define TXTN_SH_IDX   WSTL_TEXT_15_8BIT//WSTL_TEXT_28_8BIT //WSTL_TEXT_01_8BIT //WSTL_TEXT_13
#define TXTN_HL_IDX   WSTL_TEXT_28_8BIT//WSTL_BUTTON_02_FG
#define TXTN_SL_IDX   WSTL_TEXT_15_8BIT//WSTL_TEXT_28_8BIT //WSTL_TEXT_01_8BIT //WSTL_TEXT_13
#define TXTN_GRY_IDX  WSTL_TEXT_14

#ifndef SD_UI
#ifdef SUPPORT_CAS_A
#define	W_L     74//50//100  //50//14
#else
#define	W_L     50//100  //50//14
#endif
#define	W_T     60//100  //30
#define	W_W     409 //250
#define	W_H     572 //562 //370


#if Maker_GUI_ON
#define TILLE_OFFSET  0
#define TITLE_L	  (W_L)//50
#define TITLE_T   (W_T)
#define TITLE_W   (W_W )//180
#define TITLE_H   68
#else
#define TILLE_OFFSET  80
#define TITLE_L	  (W_L + TILLE_OFFSET)//50
#define TITLE_T   (W_T)
#define TITLE_W   (W_W - TILLE_OFFSET*2)//180
#define TITLE_H   68
#endif

#define INFO_L	(W_L+50)//40
#define INFO_T 	(W_T + W_H - 50)//370
#define INFO_W 	300//200
#define INFO_H 	30//24

//#define LST_L	(W_L + 2)
//#define LST_T	68
//#define LST_W	230
//#define LST_H	298

#define CON_L	(W_L + 18)//18
#define CON_T	(W_T + 70) //(W_T + 60)//76
#define CON_W	(W_W - 60)//342//232
#define CON_H	40//26
#define CON_GAP 4///2

#define SCB_L (CON_L + CON_W + 10)//(W_L + W_W - SCB_W)
#define SCB_T CON_T//68
#define SCB_W 12
#define SCB_H ((CON_H+CON_GAP)*LIST_CNT) //298

#define SCB_GAP 4

#define BMP_L_OF		8
#define BMP_T_OF		((CON_H - BMP_H)/2)
#define BMP_W			30
#define BMP_H			28

#define TXTI_L_OF  	5
#define TXTI_T_OF 	0
#define TXTI_W		70+3+30 //70
#define TXTI_H		CON_H

#define TXTN_L_OF	(TXTI_L_OF + TXTI_W + 10)
#define TXTN_T_OF   0
#define TXTN_W		(CON_W - TXTN_L_OF-10)
#define TXTN_H      CON_H
#else

#if defined(_VMX_CA_STD_ENABLE_) || defined(_VMX_CA_ENABLE_)
#define	W_L     W_LCL_L
#define	W_T     W_LCL_T
#define	W_W    	W_LCL_W
#define	W_H     W_LCL_H
#else
#define	W_L     14//100  //50//14
#define	W_T     30//100  //30
#define	W_W     255 //250
#define	W_H     425 //562 //370
#endif

//#define TILLE_OFFSET  80
#define TITLE_L	  55//(W_L + TILLE_OFFSET)//50
#define TITLE_T   (W_T)
#define TITLE_W   170//(W_W - TILLE_OFFSET*2)//180
#define TITLE_H   36



//#define LST_L	(W_L + 2)
//#define LST_T	68
//#define LST_W	230
//#define LST_H	298

#define CON_L	23//(W_L + 18)//18
#define CON_T	76//(W_T + 70) //(W_T + 60)//76
#define CON_W	225//(W_W - 60)//342//232
#define CON_H	32//26
#define CON_GAP 1///2

#define INFO_L	35//40
#define INFO_T 	(W_T + W_H - 43)//370
#define INFO_W 	210//200
#define INFO_H 	24//24

#define SCB_L (W_L + W_W - SCB_W-6)//(W_L + W_W - SCB_W)
#define SCB_T 74//68
#define SCB_W 12
#define SCB_H 310//((CON_H+CON_GAP)*LIST_CNT) //298

#define SCB_GAP 4

#define BMP_L_OF		8
#define BMP_T_OF		((CON_H - BMP_H)/2)
#define BMP_W			30
#define BMP_H			28

#define TXTI_L_OF  	3
#define TXTI_T_OF 	0
#define TXTI_W		50 //70
#define TXTI_H		CON_H

#define TXTN_L_OF	(TXTI_L_OF + TXTI_W + 10)
#define TXTN_T_OF   0
#define TXTN_W		(CON_W - TXTN_L_OF-10)
#define TXTN_H      CON_H

#endif

#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    lcl_item_con_keymap,lcl_item_con_callback,  \
    conobj, ID,1)

#define LDEF_BMP(root,varbmp,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,bmpID)		\
    DEF_BITMAP(varbmp,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, BMP_SH_IDX,BMP_HL_IDX,BMP_SL_IDX,BMP_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,bmpID)

#define LDEF_TXTIDX(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, TXTI_SH_IDX,TXTI_HL_IDX,TXTI_SL_IDX,TXTI_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_RIGHT| C_ALIGN_VCENTER, 0,0,resID,str)
    

#define LDEF_TXTNAME(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, TXTN_SH_IDX,TXTN_HL_IDX,TXTN_SL_IDX,TXTN_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,str)

#define LDEF_LCL_ITEM(root,varCon,nxtObj,varBmp,varTxtidx,varTxtName,ID,IDu,IDd,l,t,w,h,icon,idxstr,namestr)	\
	LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxtidx,1)	\
	LDEF_TXTIDX(&varCon,varTxtidx,&varTxtName ,0,0,0,0,0,l + TXTI_L_OF, t + TXTI_T_OF,TXTI_W,TXTI_H,0,idxstr)	\
	LDEF_TXTNAME(&varCon,varTxtName,NULL/*&varBmp*/      ,1,1,1,1,1,l + TXTN_L_OF, t + TXTN_T_OF,TXTN_W,TXTN_H,0,namestr)  \
    LDEF_BMP(&varCon,varBmp,NULL,0,0,0,0,0,l,t+h,w,SCB_GAP,0)

#define LDEF_LISTBAR(root,varScb,page,l,t,w,h)	\
	DEF_SCROLLBAR(varScb, &root, NULL, C_ATTR_ACTIVE, 0, \
		0, 0, 0, 0, 0, l, t, w, h, LIST_BAR_SH_IDX, LIST_BAR_HL_IDX, LIST_BAR_SH_IDX, LIST_BAR_SH_IDX, \
		NULL, NULL, BAR_VERT_AUTO | SBAR_STYLE_RECT_STYLE, page, LIST_BAR_MID_THUMB_IDX, LIST_BAR_MID_RECT_IDX, \
		0, 18, w, h - 36, 100, 1)

#define LDEF_OL(root,varOl,nxtObj,l,t,w,h,style,dep,count,flds,sb,mark)	\
  	DEF_OBJECTLIST(varOl,&root,nxtObj,C_ATTR_ACTIVE,0, \
    	1,1,1,1,1, l,t,w,h,LIST_SH_IDX,LIST_HL_IDX,0,0,   \
    	lcl_item_lst_keymap,lcl_item_lst_callback,    \
    	flds,sb,mark,style,dep,count,mark)


LDEF_LCL_ITEM(lcl_item_list,lcl_item_con1,&lcl_item_con2,lcl_item_bmp1,lcl_item_txtidx1,lcl_item_txtnam1, \
	1,10, 2, CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	0, display_strs[0],display_strs[15])
LDEF_LCL_ITEM(lcl_item_list,lcl_item_con2,&lcl_item_con3,lcl_item_bmp2,lcl_item_txtidx2,lcl_item_txtnam2, \
	2,1, 3, CON_L, CON_T + (CON_H + CON_GAP)*1,CON_W,CON_H,	0, display_strs[1],display_strs[16])
LDEF_LCL_ITEM(lcl_item_list,lcl_item_con3,&lcl_item_con4,lcl_item_bmp3,lcl_item_txtidx3,lcl_item_txtnam3, \
	3,2, 4, CON_L, CON_T + (CON_H + CON_GAP)*2,CON_W,CON_H,	0, display_strs[2],display_strs[17])
LDEF_LCL_ITEM(lcl_item_list,lcl_item_con4,&lcl_item_con5,lcl_item_bmp4,lcl_item_txtidx4,lcl_item_txtnam4, \
	4,3, 5, CON_L, CON_T + (CON_H + CON_GAP)*3,CON_W,CON_H,	0, display_strs[3],display_strs[18])
LDEF_LCL_ITEM(lcl_item_list,lcl_item_con5,&lcl_item_con6,lcl_item_bmp5,lcl_item_txtidx5,lcl_item_txtnam5, \
	5,4, 6, CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H,	0, display_strs[4],display_strs[19])
LDEF_LCL_ITEM(lcl_item_list,lcl_item_con6,&lcl_item_con7,lcl_item_bmp6,lcl_item_txtidx6,lcl_item_txtnam6, \
	6,5, 7, CON_L, CON_T + (CON_H + CON_GAP)*5,CON_W,CON_H,	0, display_strs[5],display_strs[20])
LDEF_LCL_ITEM(lcl_item_list,lcl_item_con7,&lcl_item_con8,lcl_item_bmp7,lcl_item_txtidx7,lcl_item_txtnam7, \
	7,6, 8, CON_L, CON_T + (CON_H + CON_GAP)*6,CON_W,CON_H,	0, display_strs[6],display_strs[21])
LDEF_LCL_ITEM(lcl_item_list,lcl_item_con8,&lcl_item_con9,lcl_item_bmp8,lcl_item_txtidx8,lcl_item_txtnam8, \
	8,7, 9, CON_L, CON_T + (CON_H + CON_GAP)*7,CON_W,CON_H,	0, display_strs[7],display_strs[22])
LDEF_LCL_ITEM(lcl_item_list,lcl_item_con9,&lcl_item_con10,lcl_item_bmp9,lcl_item_txtidx9,lcl_item_txtnam9, \
	9,8, 10, CON_L, CON_T + (CON_H + CON_GAP)*8,CON_W,CON_H,	0, display_strs[8],display_strs[23])
LDEF_LCL_ITEM(lcl_item_list,lcl_item_con10,NULL               ,lcl_item_bmp10,lcl_item_txtidx10,lcl_item_txtnam10, \
	10,9, 1, CON_L, CON_T + (CON_H + CON_GAP)*9,CON_W,CON_H,	0, display_strs[9],display_strs[24])


LDEF_LISTBAR(lcl_item_list,lcl_list_bar,LIST_CNT,SCB_L,SCB_T, SCB_W, SCB_H)



extern POBJECT_HEAD lcl_items[] ;

#define LIST_STYLE (LIST_VER | LIST_NO_SLECT | LIST_ITEMS_NOCOMPLETE |  LIST_SCROLL | LIST_GRID | LIST_FOCUS_FIRST | LIST_PAGE_KEEP_CURITEM | LIST_FULL_PAGE)

LDEF_OL(g_win_light_chanlist,lcl_item_list,&lcl_info, CON_L, CON_T, CON_W, CON_H,	\
	LIST_STYLE, LIST_CNT, 0, lcl_items,&lcl_list_bar,NULL)

#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
DEF_TEXTFIELD(lcl_title,&g_win_light_chanlist,&lcl_item_list,C_ATTR_ACTIVE,0, \
    0,0,0,0,0,TITLE_L,TITLE_T ,TITLE_W,TITLE_H, TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_TOP, 0,8,RS_CHANNEL_TV_CHANNEL_LIST,NULL)
#else
DEF_TEXTFIELD(lcl_title,&g_win_light_chanlist,&lcl_item_list,C_ATTR_ACTIVE,0, \
    0,0,0,0,0,TITLE_L,TITLE_T ,TITLE_W,TITLE_H, TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_TOP, 0,8,0,display_strs[30])
#endif

DEF_TEXTFIELD(lcl_info,&g_win_light_chanlist,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0,INFO_L, INFO_T ,INFO_W,INFO_H, INFO_SH_IDX,INFO_SH_IDX,INFO_SH_IDX,INFO_SH_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,0,display_strs[31])


DEF_CONTAINER(g_win_light_chanlist,NULL,NULL,C_ATTR_ACTIVE,0, \
    1,0,0,0,0, W_L,W_T,W_W,W_H, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    lcl_con_keymap,lcl_con_callback,  \
    (POBJECT_HEAD)&lcl_title, 1,0)

#if 0

/**************************** Start of channel infor ******************************/
extern CONTAINER   	lcl_info_con;
extern TEXT_FIELD 	lcl_info_playchname_txt;
extern TEXT_FIELD 	lcl_info_hilitechname_txt;
extern TEXT_FIELD 	lcl_info_preepgname_txt;
extern TEXT_FIELD 	lcl_info_preepgtime_txt;
extern BITMAP		lcl_infor_grpflag_bmp;
extern TEXT_FIELD 	lcl_info_grpname_txt;
extern BITMAP		lcl_infor_hilitechca_bmp;
/**************************** End of channel infor ******************************/


#define	WI_L     (W_L + W_W + 20)
#define	WI_T     (W_T + W_H - WI_H)
#define	WI_W     206
#define	WI_H     180

#define TXTP_L	WI_L
#define TXTP_T	WI_T
#define TXTP_W	WI_W
#define TXTP_H	36

#define TXTH_L	(WI_L + 13)
#define TXTH_T (WI_T + TXTP_H + 4)
#define TXTH_W (WI_W - 26)
#define TXTH_H 28

#define TXTEN_L	 TXTH_L
#define TXTEN_T (TXTH_T + TXTH_H)
#define TXTEN_W	 TXTH_W
#define TXTEN_H	 TXTH_H

#define TXTET_L	 TXTH_L
#define TXTET_T (TXTEN_T + TXTEN_H)
#define TXTET_W	 TXTH_W
#define TXTET_H	 TXTH_H

#define BMPG_L	TXTH_L
#define BMPG_T	(TXTET_T + TXTET_H)
#define BMPG_W	30
#define BMPG_H	30

#define TXTG_L	 (BMPG_L + BMPG_W)
#define TXTG_T (TXTET_T + TXTET_H)
#define TXTG_W	 170
#define TXTG_H	 30

#define BMPC_L	(TXTG_L + TXTG_W)
#define BMPC_T	(TXTET_T + TXTET_H)
#define BMPC_W	30
#define BMPC_H	30

#define WINI_SH_IDX	WSTL_TITLE_03
#define TXTP_SH_IDX	WSTL_MIXBACK_WHITE_IDX
#define TXTH_SH_IDX	WSTL_MIXBACK_WHITE_IDX
#define TXTEN_SH_IDX	WSTL_MIXBACK_WHITE_IDX
#define TXTET_SH_IDX	WSTL_MIXBACK_WHITE_IDX
#define BMPG_SH_IDX	WSTL_MIXBACK_WHITE_IDX
#define TXTG_SH_IDX	WSTL_MIXBACK_WHITE_IDX
#define BMPC_SH_IDX	WSTL_MIXBACK_WHITE_IDX

#define LDEF_I_TXT(root,varTxt,nxtObj,l,t,w,h,sh,str,font,ox)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,font, \
    0,0,0,0,0, l,t,w,h, sh,sh,sh,sh,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, ox,0,0,str)    

#define LDEF_I_BMP(root,varbmp,nxtObj,l,t,w,h,sh)		\
    DEF_BITMAP(varbmp,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, sh,sh,sh,sh,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,0)

LDEF_I_TXT(lcl_info_con,lcl_info_playchname_txt,&lcl_info_hilitechname_txt,	\
		TXTP_L, TXTP_T, TXTP_W, TXTP_H,TXTP_SH_IDX,display_strs[31],1, 10)
LDEF_I_TXT(lcl_info_con,lcl_info_hilitechname_txt,&lcl_info_preepgname_txt,	\
		TXTH_L, TXTH_T, TXTH_W, TXTH_H,TXTH_SH_IDX,display_strs[32],0,0)
LDEF_I_TXT(lcl_info_con,lcl_info_preepgname_txt,&lcl_info_preepgtime_txt,	\
		TXTEN_L, TXTEN_T, TXTEN_W, TXTEN_H,TXTEN_SH_IDX,display_strs[33],0,0)
LDEF_I_TXT(lcl_info_con,lcl_info_preepgtime_txt,&lcl_infor_grpflag_bmp,	\
		TXTET_L, TXTET_T, TXTET_W, TXTET_H,TXTET_SH_IDX,display_strs[34],0,0)
LDEF_I_BMP(lcl_info_con,lcl_infor_grpflag_bmp,&lcl_info_grpname_txt,	\
		BMPG_L, BMPG_T, BMPG_W, BMPG_H,BMPG_SH_IDX)
LDEF_I_TXT(lcl_info_con,lcl_info_grpname_txt,&lcl_infor_hilitechca_bmp,	\
		TXTG_L, TXTG_T, TXTG_W, TXTG_H,TXTG_SH_IDX,display_strs[35],0,0)
LDEF_I_BMP(lcl_info_con,lcl_infor_hilitechca_bmp, NULL ,	\
		BMPC_L, BMPC_T, BMPC_W, BMPC_H,BMPC_SH_IDX)

DEF_CONTAINER(lcl_info_con,NULL,NULL,C_ATTR_ACTIVE,0, \
    1,0,0,0,0, WI_L,WI_T,WI_W,WI_H, WINI_SH_IDX,WINI_SH_IDX,WINI_SH_IDX,WINI_SH_IDX,   \
    NULL,NULL,  \
    (POBJECT_HEAD)&lcl_info_playchname_txt, 1,0)
#endif

/*******************************************************************************
*	Local variables define
*******************************************************************************/
POBJECT_HEAD lcl_items[] = 
{
	(POBJECT_HEAD)&lcl_item_con1,
	(POBJECT_HEAD)&lcl_item_con2,
	(POBJECT_HEAD)&lcl_item_con3,
	(POBJECT_HEAD)&lcl_item_con4,
	(POBJECT_HEAD)&lcl_item_con5,
	(POBJECT_HEAD)&lcl_item_con6,
	(POBJECT_HEAD)&lcl_item_con7,
	(POBJECT_HEAD)&lcl_item_con8,
	(POBJECT_HEAD)&lcl_item_con9,
	(POBJECT_HEAD)&lcl_item_con10,
};
static UINT8 only_fav_grp;

BOOL open_pip_list = FALSE;

/*******************************************************************************
*	Function declare
*******************************************************************************/
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_ON)//ChengYu@20131014, disable change group function
void win_lcl_set_title(BOOL update);
#endif
void win_lcl_set_display(void);
static void win_lcl_display_infor(BOOL update);
static void	win_lcl_load_group(UINT8 grp_idx,BOOL update);
static void win_lcl_play_channel(UINT16 chan_idx);
static PRESULT 	win_lcl_message_proc(UINT32 msg_type, UINT32 msg_code);
/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/
static VACTION lcl_item_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
	default:	
		act = VACT_PASS;
	}

	return act;
}


static PRESULT lcl_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;

	return ret;
}

static VACTION act_rec;

static VACTION lcl_item_lst_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
	case V_KEY_UP:
		act_rec=act = VACT_CURSOR_UP;
		break;		
	case V_KEY_DOWN:
		act_rec=act = VACT_CURSOR_DOWN;
		break;
	case V_KEY_P_UP:
		act = VACT_CURSOR_PGUP;
		break;
	case V_KEY_P_DOWN:
		act = VACT_CURSOR_PGDN;
		break;
		
 	case V_KEY_ENTER:
		act = VACT_PLAY_CH;	/* Play */
		break;
	case V_KEY_TVRADIO:
		act = VACT_TV_RADIO_SW;
		break;
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_ON)//ChengYu@20131014, disable change group function	
	case V_KEY_LEFT:
		act = VACT_GROUP_DECREASE;
		break;
	case V_KEY_RIGHT:
		act  = VACT_GROUP_INCREASE;
		break;
	case V_KEY_SAT:
		act  = VACT_GROUP_ALL_SELECT;
		break;
#endif		
	case V_KEY_FAV:
		act  = VACT_GROUP_FAV_SELECT;		
		break;
	default:
		act = VACT_PASS;
			
	}
	
	return act;

}
static void win_lcl_clean_valid_item(void)
{
	OBJLIST* ol = &lcl_item_list;
	UINT16 top,cnt,page,chan_idx;
	UINT32 i;
	P_NODE p_node;
	TEXT_FIELD* txt;
	CONTAINER* item;
	

	for(i=0;i<10;i++)
	{
		item = (CONTAINER*)lcl_items[i];

		txt = (TEXT_FIELD*)OSD_GetContainerNextObj(item);//bmp->head.pNext;

		/*Name*/
		txt = (TEXT_FIELD*)OSD_GetObjpNext(txt);//txt->head.pNext;

		OSD_SetAttr(item, C_ATTR_ACTIVE);
		OSD_SetAttr(txt, C_ATTR_ACTIVE);
	}	
}

static void win_lcl_set_valid_item(void)
{
	OBJLIST* ol = &lcl_item_list;
	UINT16 top,cnt,page,chan_idx;
	UINT32 i;
	P_NODE p_node;
	TEXT_FIELD* txt;
	CONTAINER* item;
	
	cnt = OSD_GetObjListCount(ol);
	page = OSD_GetObjListPage(ol); 
	top = OSD_GetObjListTop(ol);
	
	for(i=0;i<page;i++)
	{
		item = (CONTAINER*)lcl_items[i];

		chan_idx = top + i;
		
		if(chan_idx >= cnt)
			break;
		
		get_prog_at(chan_idx,&p_node);	
		txt = (TEXT_FIELD*)OSD_GetContainerNextObj(item);//bmp->head.pNext;

		/*Name*/
		txt = (TEXT_FIELD*)OSD_GetObjpNext(txt);//txt->head.pNext;
/*
		if(p_node.rec_skip_flag)
		{
			OSD_SetAttr(item, C_ATTR_INACTIVE);
			OSD_SetAttr(txt, C_ATTR_INACTIVE);
		}
		else
*/		{
			OSD_SetAttr(item, C_ATTR_ACTIVE);
			OSD_SetAttr(txt, C_ATTR_ACTIVE);
		}
	}	
}

static PRESULT lcl_item_lst_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	VACTION unact;
	OBJLIST* ol = (OBJLIST*)pObj;
	UINT32 mainsel,subsel;
	UINT8 back_saved;
	UINT8 cur_av_mode,av_mode;
	UINT8 sat_group_num;
	UINT8 cur_group_idx, group_idx,grp_idx_start,grp_idx_end;
	UINT8 group_type,group_pos;
	UINT16 channel;
	S_NODE s_node;
	BOOL  grp_chged = FALSE;
	UINT8 grp_cnt,grp_idx;
	COM_POP_LIST_PARAM_T param;
	OSD_RECT rect;
	UINT16 sel;
	UINT16 strID;
	char shift;
	COM_POP_LIST_TYPE_T list_type;
		//CONTAINER* item;
		P_NODE p_node;
		INT32  prog_index=0;
		UINT16 top_temp=0;
		//item = (CONTAINER*)lcl_items[param2-ol->wTop];
    UINT16 last_group_prog = 0xffff;
	static UINT16 last_prog_pos = 0xffff;
    P_NODE p_node_temp;
	UINT16 rec_num;
	av_mode = sys_data_get_cur_chan_mode();
	 
	switch(event)
	{
	case EVN_PRE_DRAW:
		win_lcl_set_display();
		break;
	case EVN_PRE_CHANGE:
		break;
	case EVN_ITEM_PRE_CHANGE:
		break;		
#if 1	
	case EVN_ITEM_POST_CHANGE:
		get_prog_at((UINT16)param2,&p_node);	
		prog_index=(UINT32)param2;
/*		if((p_node.rec_skip_flag)&&((act_rec==VACT_CURSOR_DOWN)||(act_rec==VACT_CURSOR_UP)))
			{
				do{
					
				if(act_rec==VACT_CURSOR_DOWN)
					prog_index++;//OSD_ObjListChgFocus(pObj,ol->wNewPoint+1, C_DRAW_SIGN_EVN_FLG | C_UPDATE_FOCUS);
				else if(act_rec==VACT_CURSOR_UP)
					prog_index--;//OSD_ObjListChgFocus(pObj,ol->wNewPoint-1, C_DRAW_SIGN_EVN_FLG | C_UPDATE_FOCUS);

				if(prog_index > (ol->wCount-1))
					prog_index=0;
				else if(prog_index < 0)
					prog_index=(ol->wCount-1);
					get_prog_at((UINT16)prog_index,&p_node);		
				}
				while(p_node.rec_skip_flag);
			}
*/		
		OSD_ChangeFocus(pObj,prog_index, C_DRAW_SIGN_EVN_FLG | C_UPDATE_FOCUS );
		win_lcl_set_valid_item();
		OSD_TrackObject((POBJECT_HEAD)ol, C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);	
		break;
#endif		
	case EVN_UNKNOWN_ACTION:
		cur_group_idx = sys_data_get_cur_group_index();
		
		unact = (VACTION)(param1>>16);
		switch(unact)
		{
		case VACT_PLAY_CH:
			sel = OSD_GetObjListCurPoint(ol);
			//win_lcl_display_infor(TRUE);

			if(sel != OSD_GetObjListSingleSelect(ol)
				|| GetChannelParrentLock() )
			{
#ifdef PIP_SUPPORT
				if(sys_data_get_pip_support() && (system_state == SYS_STATE_PIP) && open_pip_list)
				{
					ap_pip_set_chgch(TRUE);// PIP picture dmx
				}
#endif

#ifdef SAT2IP_CLIENT_SUPPORT	
			//	last_prog_pos = sys_data_get_cur_group_cur_mode_channel();
			//	get_prog_at(last_prog_pos,&p_node_temp);
			//	libc_printf("%s,prog_pos=%d,prog_id=%d\n",__FUNCTION__,last_prog_pos,p_node_temp.prog_id);
			//	get_sat_by_id(p_node.sat_id, &s_node);
				if (api_cur_prog_is_sat2ip())//(1 == s_node.sat2ip_flag)
				{
					if (api_pvr_is_recording())
					{
						win_compopup_init(WIN_POPUP_TYPE_SMSG); 					   
						win_compopup_set_frame(MSG_POPUP_LAYER_L, MSG_POPUP_LAYER_T, MSG_POPUP_LAYER_W, MSG_POPUP_LAYER_H*2);
						win_compopup_set_msg_ext("SAT>IP Stream, can not do back-ground record!", NULL,0);
						win_compopup_open_ext(&back_saved);
	
						api_stop_record(0, 0);
						api_stop_record(0, 1);
						
						osal_task_sleep(2000);
						win_compopup_smsg_restoreback();
					}
					win_satip_stop_play_channel();
					SatipClearTaskStatus();
				}
#endif

                // @HM_CONAX3515
                #if defined (MULTI_DESCRAMBLE) && !(defined(CAS9_V6) && defined(CAS9_PVR_SID))
                last_prog_pos = sys_data_get_cur_group_cur_mode_channel();
                get_prog_at(last_prog_pos,&p_node_temp);
                libc_printf("%s,prog_pos=%d,prog_id=%d\n",__FUNCTION__,last_prog_pos,p_node_temp.prog_id);
                /*stop pre channel's filter,ts_stream and so on*/
                if(api_mcas_get_prog_record_flag(p_node_temp.prog_id) == FALSE)   //if the program is recording,don't stop descramble service
                {
                    libc_printf("%s,stop service\n",__FUNCTION__);
                    api_mcas_stop_service_multi_des(p_node_temp.prog_id,0xffff);
                }
                last_prog_pos = sel;
                #endif
				win_lcl_play_channel(sel);
				OSD_SetObjListSingleSelect(ol,sel);
               // #ifdef SUPPORT_CAS9
			   #if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)
                    ret = PROC_LEAVE;
                #endif
                win_lcl_display_infor(TRUE);
			}
			else
				ret = PROC_LEAVE;
			break;
		case VACT_TV_RADIO_SW:
#if 0//def SAT2IP_SUPPORT //alan change for new spec.
            ts_route_check_record_route_all(&rec_num);
			if(rec_num > 0)
			{
				break;
			}
#else
			if(pvr_info.rec_num > 0)
			{
				break;
			}

#endif            
			av_mode = (av_mode==TV_CHAN)? RADIO_CHAN : TV_CHAN; 				
			sys_data_get_cur_group_channel(&channel, av_mode);
			if(channel==P_INVALID_ID) /* If the opposite mode has no channel */
			{
				if(av_mode==RADIO_CHAN)
	                strID = RS_MSG_NO_RADIO_CHANNEL;
	            else
	                strID = RS_MSG_NO_TV_CHANNEL;            
	            win_compopup_init(WIN_POPUP_TYPE_SMSG);
	            win_compopup_set_msg(NULL, NULL,strID);
				win_compopup_open_ext(&back_saved);
				osal_task_sleep(500);
				win_compopup_smsg_restoreback();
			}
			else
			{	
                #if defined(MULTI_DESCRAMBLE) && !(defined(CAS9_V6) && defined(CAS9_PVR_SID)) // @HM_CONAX3515
                last_prog_pos = sys_data_get_cur_group_cur_mode_channel();
                get_prog_at(last_prog_pos,&p_node_temp);
                libc_printf("%s,prog_pos=%d,prog_id=%d\n",__FUNCTION__,last_prog_pos,p_node_temp.prog_id);
                /*stop pre channel's filter,ts_stream and so on*/
                if(api_mcas_get_prog_record_flag(p_node_temp.prog_id) == FALSE)   //if the program is recording,don't stop descramble service
                {
                    libc_printf("%s,stop service\n",__FUNCTION__);
                    api_mcas_stop_service_multi_des(p_node_temp.prog_id,0xffff);
                }
                #endif

#ifdef SAT2IP_CLIENT_SUPPORT	
			//	last_prog_pos = sys_data_get_cur_group_cur_mode_channel();
            //    get_prog_at(last_prog_pos,&p_node_temp);
            //    libc_printf("%s,prog_pos=%d,prog_id=%d\n",__FUNCTION__,last_prog_pos,p_node_temp.prog_id);
			//	get_sat_by_id(p_node.sat_id, &s_node);
				if (api_cur_prog_is_sat2ip())//(1 == s_node.sat2ip_flag)
				{
					if (api_pvr_is_recording())
					{
						win_compopup_init(WIN_POPUP_TYPE_SMSG); 					   
						win_compopup_set_frame(MSG_POPUP_LAYER_L, MSG_POPUP_LAYER_T, MSG_POPUP_LAYER_W, MSG_POPUP_LAYER_H*2);
						win_compopup_set_msg_ext("SAT>IP Stream, can not do back-ground record!", NULL,0);
						win_compopup_open_ext(&back_saved);
		
						api_stop_record(0, 0);
						api_stop_record(0, 1);
						
						osal_task_sleep(2000);
						win_compopup_smsg_restoreback();
					}
					win_satip_stop_play_channel();
					SatipClearTaskStatus();
				}
#endif

				
				sys_data_set_cur_chan_mode(av_mode);
				cur_group_idx = sys_data_get_cur_group_index();
				win_lcl_load_group(cur_group_idx,TRUE);
				win_lcl_display_infor(TRUE);
				channel = OSD_GetObjListCurPoint(ol);
				win_lcl_play_channel(channel);			
			}					
			break;
			
		case VACT_GROUP_DECREASE:
		case VACT_GROUP_INCREASE:			
#ifdef PIP_SUPPORT
			if(sys_data_get_pip_support() && (system_state == SYS_STATE_PIP) && open_pip_list)
			{
				break;
			}
#endif
#ifdef NEW_DEMO_FRAME
#if 0//def SAT2IP_SUPPORT //alan change for new spec.
            ts_route_check_record_route_all(&rec_num);
			if(rec_num > 0)
			{
				break;
			}
#else
			if(pvr_info.rec_num > 0)
			{
				break;
			}

#endif            
#endif
			grp_idx = cur_group_idx;
			if(only_fav_grp)
				grp_idx_start 	= sys_data_get_sate_group_num(av_mode);// + 1;
			else
				grp_idx_start 	= 0;
			grp_idx_end 	= sys_data_get_group_num() - 1;
		
			//if(grp_cnt > 1)
			{
				if(unact == VACT_GROUP_DECREASE)
				{
					grp_idx =  (grp_idx>grp_idx_start)? (grp_idx-1) : grp_idx_end;
					//grp_idx =  (grp_idx==1)? 0:grp_idx;
				}
				else
				{
					grp_idx =  (grp_idx< grp_idx_end)? (grp_idx+1) : grp_idx_start;
					//grp_idx =  (grp_idx==1)? 2:grp_idx;
				}
			}
       /*     
        #if (SYS_PROJECT_FE == PROJECT_FE_DVBC)
            if(grp_idx == 1 && grp_idx_end == 1)
            {
                grp_idx = 0;
            }
            else if(grp_idx == 1)
            {
                if(unact == VACT_GROUP_DECREASE)
                    grp_idx--;
                else
                    grp_idx++;
            }
        
        #endif
        */
CHANGE_CH_GROUP:		
			if(grp_idx != 	cur_group_idx)
			{
                #if defined(MULTI_DESCRAMBLE) && !(defined(CAS9_V6) && defined(CAS9_PVR_SID)) // @HM_CONAX3515
                last_group_prog = sys_data_get_cur_group_cur_mode_channel();
                get_prog_at(last_group_prog,&p_node_temp);
                libc_printf("%s,prog_pos=%d,prog_id=%d\n",__FUNCTION__,last_group_prog,p_node_temp.prog_id);
                /*stop pre channel's filter,ts_stream and so on*/
                if(api_mcas_get_prog_record_flag(p_node_temp.prog_id) == FALSE)   //if the program is recording,don't stop descramble service
                {
                    libc_printf("%s,stop service\n",__FUNCTION__);
                    api_mcas_stop_service_multi_des(p_node_temp.prog_id,0xffff);
                }
                #endif
#ifdef SAT2IP_CLIENT_SUPPORT	
			//	last_prog_pos = sys_data_get_cur_group_cur_mode_channel();
			//	get_prog_at(last_prog_pos,&p_node_temp);
			//	libc_printf("%s,prog_pos=%d,prog_id=%d\n",__FUNCTION__,last_prog_pos,p_node_temp.prog_id);
			//	get_sat_by_id(p_node.sat_id, &s_node);
				if (api_cur_prog_is_sat2ip())//(1 == s_node.sat2ip_flag)
				{
					if (api_pvr_is_recording())
					{
						win_compopup_init(WIN_POPUP_TYPE_SMSG); 					   
						win_compopup_set_frame(MSG_POPUP_LAYER_L, MSG_POPUP_LAYER_T, MSG_POPUP_LAYER_W, MSG_POPUP_LAYER_H*2);
						win_compopup_set_msg_ext("SAT>IP Stream, can not do back-ground record!", NULL,0);
						win_compopup_open_ext(&back_saved);
		
						api_stop_record(0, 0);
						api_stop_record(0, 1);
						
						osal_task_sleep(2000);
						win_compopup_smsg_restoreback();
					}
					win_satip_stop_play_channel();
					SatipClearTaskStatus();
				}
#endif
                
				sys_data_get_cur_mode_group_infor( cur_group_idx, &group_type,&group_pos, &channel);
				if(group_type != FAV_GROUP_TYPE && only_fav_grp)
					only_fav_grp = 0;
				
				win_lcl_load_group(grp_idx,TRUE);
                win_lcl_display_infor(TRUE);
				sel = OSD_GetObjListCurPoint(ol);
				win_lcl_play_channel(sel);
			}

			break;
		case VACT_GROUP_ALL_SELECT:
		case VACT_GROUP_FAV_SELECT:			
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
			ret = PROC_LEAVE;
			break;
#endif
			list_type = (unact == VACT_GROUP_ALL_SELECT)? POP_LIST_TYPE_CHGRPSAT : POP_LIST_TYPE_CHGRPFAV;
			
			param.id = 0;
			param.cur = cur_group_idx;
			if(list_type == POP_LIST_TYPE_CHGRPFAV)
			{
				if(sys_data_get_fav_group_num(av_mode) == 0)
					break;
				sys_data_get_cur_mode_group_infor( cur_group_idx, &group_type,&group_pos, &channel);
				if(group_type == FAV_GROUP_TYPE)
                {
	                param.cur = sys_data_get_cur_group_index() - sys_data_get_sate_group_num(av_mode) - 1;
                }
				else
					param.cur = 0xFFFF;					
			}
			param.selecttype = POP_LIST_SINGLESELECT;	

			OSD_SetRect(&rect,CON_L,CON_T,CON_W,380);
			sel = win_com_open_sub_list(list_type,&rect,&param);
			if(list_type == POP_LIST_TYPE_CHGRPFAV)
				grp_cnt = sys_data_get_fav_group_num(av_mode);
			else
       // #if (SYS_PROJECT_FE == PROJECT_FE_DVBC)
       //		grp_cnt = 1;
       // #else                
				grp_cnt = sys_data_get_sate_group_num(av_mode) + 1;
       // #endif
			if(sel < grp_cnt)
			{
				grp_idx = (UINT8)sel;
				
				if(list_type == POP_LIST_TYPE_CHGRPFAV)
					grp_idx += sys_data_get_sate_group_num(av_mode) + 1;
				
				goto CHANGE_CH_GROUP;
			}
						
			ret = PROC_LOOP;			
			break;
		default:
			;
			
		}
	case EVN_KEY_GOT:
		win_lcl_clean_valid_item();
	break;		
	default:
		;
	}

	return ret;
}


static VACTION lcl_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;
	
	switch(key)
	{
	case V_KEY_MENU:
	case V_KEY_EXIT:		
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
	case V_KEY_FAV:
#endif
		act  = VACT_CLOSE;
		break;
	case V_KEY_LIST:
		if(system_state != SYS_STATE_PIP)
		{
			act  = VACT_CLOSE;
		}
		break;
	case V_KEY_PIP_LIST:
		if(system_state == SYS_STATE_PIP)
		{
			act  = VACT_CLOSE;
		}
		break;
	default:
		act = VACT_PASS;
		break;	
	}
	
	return act;
}

static BOOL pre_open = FALSE;
static PRESULT lcl_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT32 i;
	UINT8	unact;
	CONTAINER* cont = (CONTAINER*)pObj;
	OBJLIST* ol= &lcl_item_list;

	UINT8	id = OSD_GetObjID(pObj);
	UINT8 	save_back;
	UINT32  chan_count;
	UINT32  play_chan_idx;
	UINT8 cur_grp_idx,group_type,group_pos,num_group;
	UINT16 sel;
	UINT8 av_flag;
	static BOOL change_group = FALSE;
	UINT32 vkey;
	UINT8 back_saved;

	switch(event)
	{
	case EVN_PRE_OPEN:
		CHENGYU_PRINTF("lcl_con_callback ==> EVN_PRE_OPEN\n");
        //#ifdef SUPPORT_CAS9
        #if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)
			if(get_mmi_showed()==1||get_mmi_showed()==6)
			{
				//win_mmipopup_close(1);
					#if defined(SUPPORT_CAS7)//SUPPORT_CAS7 alone
    						win_mmipopup_close(1);
    					#else
						win_pop_msg_close(1);
					#endif
				//win_fingerpop_close();
			}
			if((0==get_mmi_showed()) && (GetSignalStatausShow()))
				ShowSignalStatusOSDOnOff(0);
        #endif	
		change_group = 0;
		
		only_fav_grp = 0;
		vkey = param2 & MENU_OPEN_PARAM_MASK;
		if( (param2 & MENU_OPEN_TYPE_MASK) == MENU_OPEN_TYPE_KEY)
		{
			if( (param2 & MENU_OPEN_PARAM_MASK ) == V_KEY_FAV)
			{
				only_fav_grp = 1;
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
				av_flag = sys_data_get_cur_chan_mode();
				if(sys_data_get_fav_group_num(av_flag) == 0)
				{
					win_compopup_init(WIN_POPUP_TYPE_SMSG);
					win_compopup_set_msg_ext(NULL, NULL, RS_POPUP_NO_FAV_CHANNEL);
					win_compopup_open();			
					osal_task_sleep(1000);
					win_compopup_close();
					return PROC_LEAVE;
				}
#endif				
			}
			if(vkey == V_KEY_PIP_LIST)
			{
				open_pip_list = TRUE;
			}		
		}
		else if( (param2 & MENU_OPEN_TYPE_MASK) == MENU_OPEN_TYPE_OTHER)
			change_group = 1;

		if(only_fav_grp)
		{
			av_flag = sys_data_get_cur_chan_mode();
			if(sys_data_get_fav_group_num(av_flag) == 0)
				return PROC_LEAVE;
		}
		
		cur_grp_idx = sys_data_get_cur_group_index();
		sys_data_get_cur_mode_group_infor(cur_grp_idx,&group_type, &group_pos, &sel);

		
		if(only_fav_grp && group_type != FAV_GROUP_TYPE)
		{
			change_group = 1;
			
			num_group = sys_data_get_group_num();
			for(;cur_grp_idx<num_group;cur_grp_idx++)
			{
				sys_data_get_cur_mode_group_infor(cur_grp_idx,&group_type, &group_pos,&sel);
				if(group_type==FAV_GROUP_TYPE)
				{
					sys_data_set_cur_group_index(cur_grp_idx);
	                break;
				}
			}
		}
#if (CC_ON==1)
			cc_vbi_show_on(FALSE);
#endif
        api_inc_wnd_count();
		
		pre_open = TRUE;
		win_lcl_load_group(cur_grp_idx,FALSE);
		pre_open = FALSE;
		//win_lcl_set_valid_item();
		//shift_signal_osd();//shift signal osd to avoid overlap

#ifdef PIP_SUPPORT
		if(sys_data_get_pip_support() && (system_state == SYS_STATE_PIP) && open_pip_list)
		{
			change_group = 0;

			if(pip_get_pos() > 1) //LT or LB
			{
				OSD_MoveObject((POBJECT_HEAD)&g_win_light_chanlist, W_L+250, W_T, FALSE);
			}
			else
			{
				OSD_MoveObject((POBJECT_HEAD)&g_win_light_chanlist, W_L, W_T, FALSE);
			}
		}
		else
#endif
		{
			OSD_MoveObject((POBJECT_HEAD)&g_win_light_chanlist, W_L, W_T, FALSE);
		}
		break;
	
	case EVN_POST_OPEN:
		win_lcl_display_infor(TRUE);		
		if(change_group && (system_state != SYS_STATE_PIP))
		{
		    menu_stack_push(pObj); /* Patch of clear no signal OSD issue in api_play_channel */

#ifdef SAT2IP_CLIENT_SUPPORT
			if (api_cur_prog_is_sat2ip())//(1 == s_node.sat2ip_flag)
			{
				if (api_pvr_is_recording())
				{
					win_compopup_init(WIN_POPUP_TYPE_SMSG); 					   
					win_compopup_set_frame(MSG_POPUP_LAYER_L, MSG_POPUP_LAYER_T, MSG_POPUP_LAYER_W, MSG_POPUP_LAYER_H*2);
					win_compopup_set_msg_ext("SAT>IP Stream, can not do back-ground record!", NULL,0);
					win_compopup_open_ext(&back_saved);
		
					api_stop_record(0, 0);
					api_stop_record(0, 1);
						
					osal_task_sleep(2000);
					win_compopup_smsg_restoreback();
				}
				win_satip_stop_play_channel();
				SatipClearTaskStatus();
			}
#endif
			
			sel = OSD_GetObjListCurPoint(ol);
			win_lcl_play_channel(sel);
            menu_stack_pop();       /* Patch of clear no signal OSD issue in api_play_channel */            
		}
		break;		
	case EVN_PRE_CLOSE:
		//restore_signal_osd();//shift back
		sys_data_save(1);		
		break;
	case EVN_POST_CLOSE:
 		open_pip_list = FALSE;
       api_dec_wnd_count();
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
		P_NODE p_node;
		sel = OSD_GetObjListCurPoint(ol);
		if(get_prog_at(sel, &p_node) != SUCCESS)
		{
			break;
		}	
		sys_data_set_cur_group_index(0);
		sys_data_change_group(0); /*  Switch to all sate group */
		play_chan_idx = get_prog_pos(p_node.prog_id);
		sys_data_set_cur_group_channel(play_chan_idx);
#endif
//#ifdef SUPPORT_CAS9
#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)
restore_ca_msg_when_exit_win();
#endif
#if (CC_ON==1)
			cc_vbi_show_on(TRUE);
#endif
		break;
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact >= VACT_NUM_1 && unact<= VACT_NUM_9)
		{
			UINT32 para = C_DRAW_SIGN_EVN_FLG | C_UPDATE_FOCUS;
			OSD_ChangeFocus(pObj,unact - VACT_NUM_0, para);
		}		
		break;
	case EVN_MSG_GOT:
		ret = win_lcl_message_proc(param1,param2);
		break;
	default:
		;
	}

	return ret;


}

static PRESULT 	win_lcl_message_proc(UINT32 msg_type, UINT32 msg_code)
{
	PRESULT ret = PROC_LOOP;
	OBJLIST* ol;
    UINT16 play_ch_idx;

	ol = &lcl_item_list;

	switch(msg_type)
	{
#if 0 // play channel is done in ap_pidchg_message_proc(), no need to do again
	case CTRL_MSG_SUBTYPE_CMD_PIDCHANGE:
#if(CHAN_NORMAL_PLAY_TYPE == 0)
        play_ch_idx = OSD_GetObjListSingleSelect(ol);
#else
        play_ch_idx = OSD_GetObjListCurPoint(ol);
#endif
		if(play_ch_idx < OSD_GetObjListCount(ol))
			win_lcl_play_channel(play_ch_idx);
		break;
#endif
	case CTRL_MSG_SUBTYPE_CMD_UPDATE_VIEW:
		win_lcl_load_group(sys_data_get_cur_group_index(), TRUE);
		break;
	default:
		ret = PROC_PASS;
		
	}

	return ret;
}

/*******************************************************************************
*	Other functions
*******************************************************************************/
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_ON)//ChengYu@20131014, disable change group function
void win_lcl_set_title(BOOL update)
{
	TEXT_FIELD* txt;
	UINT8 group_type,  group_pos;
	UINT16 channel;
	UINT16 group_name[30];
	char title[30], temp_title[30];

	txt = &lcl_title;

	get_cur_group_name((char*)group_name,&group_type);
	if((system_state == SYS_STATE_PIP) && open_pip_list)
	{
		ComUniStrToAsc((UINT8 *)group_name, temp_title);
		sprintf(title, "%s   %s", " ", temp_title);
		OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)title);
	}
	//must fix when allow to channel change when recording
	//CAS_FIX
	#ifdef SUPPORT_CAS7
	else if(api_pvr_is_recording())
		{
		sprintf(title, "%s ", "[recording]");
		OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)title);
		}
	#endif
	else
	{
	OSD_SetTextFieldContent(txt, STRING_UNICODE, (UINT32)group_name);
	}

	if(update)
		OSD_DrawObject( (POBJECT_HEAD)txt, C_UPDATE_ALL);
}
#endif
 
void win_lcl_set_display(void)
{
	UINT32 i;
	UINT16 top,cnt,page, chan_idx;
	
	OBJLIST* ol = &lcl_item_list;
	BITMAP* bmp;
	TEXT_FIELD* txt;
	CONTAINER* item;
	P_NODE p_node;
    T_NODE t_node;
	UINT32 valid_idx;
    char   str[10];

    CHENGYU_PRINTF("win_lcl_set_display ==>\n");
    
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
	UINT8 idx_str[5];
	UINT8 group_index;
	UINT32 prog_num;
#endif

	cnt = OSD_GetObjListCount(ol);
	page = OSD_GetObjListPage(ol); 
	top = OSD_GetObjListTop(ol);
	UINT16 unistr[50];
	
        //add on 2011-11-02 for BUG43260
        UINT8 frontend_kind=0;
        frontend_kind = get_combo_config_frontend();

	for(i=0;i<page;i++)
	{
		item = (CONTAINER*)lcl_items[i];

		chan_idx = top + i;
		
		if(chan_idx< cnt)
			valid_idx = 1;
		else
			valid_idx = 0;
		
		if(valid_idx)
		{
		#ifdef SUPPORT_CAS7
		if(api_pvr_is_recording())
			{
			sys_data_get_curprog_info(&p_node);
			get_tp_by_id(p_node.tp_id, &t_node);
			}
		else
			{
			get_prog_at(chan_idx,&p_node);		
		    get_tp_by_id(p_node.tp_id, &t_node);
			}
		#else
		get_prog_at(chan_idx,&p_node);		
		get_tp_by_id(p_node.tp_id, &t_node);
		#endif
		}
		/*IDX */
		txt = (TEXT_FIELD*)OSD_GetContainerNextObj(item);//bmp->head.pNext;
		if(valid_idx)
		{
#if 0		
#ifdef _LCN_ENABLE_
            if(sys_data_get_cur_group_sat_id() == get_frontend_satid(FRONTEND_TYPE_T, 1) && sys_data_get_LCN())  
                sprintf(str,"%02d-%01d%1d", t_node.remote_control_key_id, (p_node.prog_number & 0x1f)>>3, (p_node.prog_number & 0x07)+1);
            else if(/*sys_data_get_cur_group_index() == get_frontend_satid(FRONTEND_TYPE_T, 0) &&*/ sys_data_get_LCN())
                sprintf(str,"%04d",p_node.LCN);           
            else
#endif                
			    sprintf(str,"%04d",chan_idx + 1);
#endif
#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
			group_index=sys_data_get_cur_group_index();
			if(group_index != 0 && !(sys_data_get_LCN()))//ChengYu@20131031, consider enable LCN case
			{
				sys_data_change_group(0);
				prog_num = get_prog_pos(p_node.prog_id)+1;
				sys_data_change_group(group_index);
				sprintf(idx_str, "%04d\n", prog_num);
			}
			else
			{
				set_combo_chan_idx(frontend_kind, t_node, p_node, chan_idx, idx_str); 
			}
			OSD_SetTextFieldContent(txt, STRING_ANSI, idx_str);
#else			
            set_combo_chan_idx(frontend_kind, t_node, p_node, chan_idx, str);  
            OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)str);          
//			OSD_SetTextFieldContent(txt,STRING_NUMBER, chan_idx + 1);
#endif
		}
		else
			OSD_SetTextFieldContent(txt,STRING_ANSI,(UINT32)"");

		/*Name*/
		txt = (TEXT_FIELD*)OSD_GetObjpNext(txt);//txt->head.pNext;
		if(valid_idx)
		{
			if(p_node.ca_mode)
				ComAscStr2Uni("$",unistr);
			ComUniStrCopyChar((UINT8*)&unistr[p_node.ca_mode], p_node.service_name);			
			OSD_SetTextFieldContent(txt, STRING_UNICODE, (UINT32)unistr);
		}
		else
			OSD_SetTextFieldContent(txt,STRING_ANSI,(UINT32)"");
	}
	
}


static void win_lcl_display_infor(BOOL update)
{
	TEXT_FIELD* txt;
	OBJLIST		*ol;
	UINT16 channel;
	P_NODE p_node;
	T_NODE t_node;

	char str[50];
    char *FFT, *modulation;

	//UINT8 NIM_FFT,NIM_modulation;
	//struct nim_device* priv_nim_dev = NULL;
	//struct ts_route_info ts_route;
	UINT8 chan_nim_id=0;
	txt = &lcl_info;

	ol = &lcl_item_list;
	channel = OSD_GetObjListCurPoint(ol);

	get_prog_at(channel,&p_node);
	get_tp_by_id(p_node.tp_id, &t_node);
	if(t_node.ft_type == FRONTEND_TYPE_T)
	{
		/*
		ts_route_get_by_type(TS_ROUTE_MAIN_PLAY, NULL, &ts_route);
		if(ts_route.nim_id == 0)
			priv_nim_dev = g_nim_dev;
		else if(ts_route.nim_id == 1)
			priv_nim_dev = g_nim_dev2;
		*/

		if(board_get_frontend_type(0)==FRONTEND_TYPE_T)
		{
//    		priv_nim_dev = g_nim_dev;
    		chan_nim_id=0;
		}
		else
		{
//    		priv_nim_dev = g_nim_dev2;
    		chan_nim_id=1;
		}



/* 20140618 get information form DB, not form NIM*/        
//		NIM_FFT = 0;
//		NIM_modulation = 0;
//		if(priv_nim_dev != NULL)
//		{
//            INT8 timeout = 0;
//            while((NIM_FFT == 0)||(NIM_modulation == 0) || (NIM_FFT == 0xFF)||(NIM_modulation == 0xFF) )
//            {
//    			if(priv_nim_dev->get_fftmode)
//    				priv_nim_dev->get_fftmode(priv_nim_dev,&NIM_FFT);
//    			if(priv_nim_dev->get_modulation)
//    				priv_nim_dev->get_modulation(priv_nim_dev,&NIM_modulation);
//        		timeout++;
//        		osal_task_sleep(10);
//        		if( timeout == 100 )
//        			break;
//    		}	    
//		}
//		t_node.FFT = NIM_FFT;
//		t_node.modulation = NIM_modulation;
	}
    if(t_node.ft_type == FRONTEND_TYPE_C)
	    sprintf(str,"%d/%d/%s",t_node.frq*10,t_node.sym,QamTable[t_node.FEC_inner - 4]);
    else if(t_node.ft_type == FRONTEND_TYPE_S)
	    sprintf(str,"%d/%d/%c",t_node.frq,t_node.sym,t_node.pol == 0? 'H' : 'V');
    else if(t_node.ft_type == FRONTEND_TYPE_T)
    {
        FFT = "";
        if (t_node.FFT == 2)
            FFT = "2K";
        else if (t_node.FFT == 8)
            FFT = "8K";
        else if (t_node.FFT == 1)
            FFT = "1K";
        else if (t_node.FFT == 4)
            FFT = "4K";
        else if (t_node.FFT == 16)
            FFT = "16K";
        else if (t_node.FFT == 32)
            FFT = "32K";
        
        modulation = "";
        if (t_node.modulation == 2)
            modulation = "DQPSK";
        else if (t_node.modulation == 4)
            modulation = "QPSK";
        else if (t_node.modulation == 16)
            modulation = "16QAM";
        else if (t_node.modulation == 64)
            modulation = "64QAM";
        else if (t_node.modulation == (64+1))
            modulation = "256QAM";
 
	//modify for TV list frequce show error 2011 11 04
	//sprintf(str,"%d",t_node.frq);
    	if(""!=FFT)
    	{
        	strcat(str,"/");
        	strcat(str,FFT);
    	}
    	if(""!=modulation)
    	{
        	strcat(str,"/");
        	strcat(str,modulation);
    	}
    //  sprintf(str,"%d/%s/%s", t_node.frq, FFT, modulation);
	//modify end
    // if(ts_route.nim_id == 0)
        if(chan_nim_id==0)
        {
         	if(board_frontend_is_isdbt(0))
     	 	{
             	sprintf(str,"%d/%dM/%s",t_node.frq,t_node.bandwidth,modulation);
            	#ifdef BIDIRECTIONAL_OSD_STYLE
            	if (OSD_GetMirrorFlag() == TRUE)
            			sprintf(str,"%s/%dM/%d",modulation,t_node.bandwidth,t_node.frq);
            	#endif
     	 	}
    		else
    		{
    			sprintf(str,"%d/%s/%s", t_node.frq, FFT, modulation);
    			#ifdef BIDIRECTIONAL_OSD_STYLE
    			if (OSD_GetMirrorFlag() == TRUE)
            			sprintf(str,"%s/%s/%d",modulation , FFT, t_node.frq);
    			#endif
    		}
    		 	
         }
         //else  if(ts_route.nim_id == 1)
         else if(chan_nim_id==1)
    	 {
    	 	if(board_frontend_is_isdbt(1))
     		{
    		    sprintf(str,"%d/%dM/%s",t_node.frq,t_node.bandwidth,modulation);
    			#ifdef BIDIRECTIONAL_OSD_STYLE
    			if (OSD_GetMirrorFlag() == TRUE)
        				sprintf(str,"%s/%dM/%d",modulation,t_node.bandwidth,t_node.frq);
    			#endif
     		}
    		 else
    	 	{
    		    sprintf(str,"%d/%s/%s", t_node.frq, FFT, modulation);
    			#ifdef BIDIRECTIONAL_OSD_STYLE
    			if (OSD_GetMirrorFlag() == TRUE)
        				sprintf(str,"%s/%s/%d",modulation , FFT, t_node.frq);
    			#endif
    	 	}
    			
        }
    }
    
	OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)str);
	if(update)
		OSD_DrawObject((POBJECT_HEAD)txt, C_UPDATE_ALL);
}

extern P_NODE playing_pnode;
static void	win_lcl_load_group(UINT8 grp_idx,BOOL update)
{
	UINT8 group_type,  group_pos;
	UINT16 channel,ch_cnt,page;
	UINT8 av_flag;
	OBJLIST		*ol;
	P_NODE *prog_node = NULL;
	UINT16 rec_num = 0;
	ol = &lcl_item_list;

	page = OSD_GetObjListPage(ol); 

#if 0 //def SAT2IP_SUPPORT //alan change for new spec.
    ts_route_check_record_route_all(&rec_num);
#endif
    
	if(((system_state == SYS_STATE_PIP) 
#ifdef DVR_PVR_SUPPORT
		|| (ap_pvr_set_state() == PVR_STATE_REC) || (pvr_info.pvr_state == PVR_STATE_REC_TMS) || (pvr_info.pvr_state == PVR_STATE_REC_REC)
#endif
		) /*&& (1 != sat_fav_list_flag) */
		  ||(open_pip_list) 
#ifdef SAT2IP_SUPPORT
        || (rec_num > 0) 
#endif
        )
	{
		prog_node = &playing_pnode;
		sys_data_change_normal_tp(*prog_node);
		
		av_flag = sys_data_get_cur_chan_mode();
		//ch_cnt = get_prog_num(VIEW_SINGLE_TP | av_flag, prog_node->tp_id);
		ch_cnt = get_prog_num(VIEW_ALL | av_flag, 0);
		channel = get_prog_pos(prog_node->prog_id);
	}
	else	
	{
		if(only_fav_grp == 1 || pre_open == FALSE)//if not change group, no need to recreate view, to speed up UI when DB full
			sys_data_change_group(grp_idx);
		sys_data_get_cur_mode_group_infor(grp_idx,&group_type, &group_pos, &channel);

		av_flag = sys_data_get_cur_chan_mode();
		ch_cnt = get_prog_num(VIEW_ALL | av_flag, 0);

		page = OSD_GetObjListPage(ol); 	
		if(channel >= ch_cnt)
			channel = 0;
	}
//must fix when allow to channel change when recording
//CAS_FIX
	#ifdef SUPPORT_CAS7 //first we don't allow to channel change when recording ,so do this 
	if(api_pvr_is_recording())
	ch_cnt = 1;
	#endif

	OSD_SetObjListCount(ol, ch_cnt);
	OSD_SetObjListCurPoint(ol, channel);
	OSD_SetObjListNewPoint(ol, channel);
	OSD_SetObjListTop(ol, channel / page*page);
#if(CHAN_NORMAL_PLAY_TYPE == 0)
	OSD_SetObjListSingleSelect(ol, channel);
#else
	OSD_SetObjListSingleSelect(ol, INVALID_POS_NUM);
#endif

#if (AOV_CHANGE_GROUP_ENABLE == SYS_FUNC_OFF)//ChengYu@20131014, disable change group function
	CHENGYU_PRINTF("win_lcl_load_group ==> group_type(%u) update(%u)\n",group_type,update);
	if(group_type == FAV_GROUP_TYPE)
		OSD_SetTextFieldContent(&lcl_title,STRING_ID,RS_FAVORITE);
	else
	{
		if(sys_data_get_cur_chan_mode() == TV_CHAN)
			OSD_SetTextFieldContent(&lcl_title,STRING_ID,RS_CHANNEL_TV_CHANNEL_LIST);
		else
			OSD_SetTextFieldContent(&lcl_title,STRING_ID,RS_CHANNEL_RADIO_CHANNEL_LIST);
	}
#else
	win_lcl_set_title(update);
#endif
	win_lcl_display_infor(update);

	if(update)
		OSD_TrackObject( (POBJECT_HEAD)ol, C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
}

static void win_lcl_play_channel(UINT16 chan_idx)
{
#if (defined(NEW_DEMO_FRAME) && defined(CC_USE_TSG_PLAYER) && defined(DVR_PVR_SUPPORT))

    P_NODE p_node;
	UINT16 cur_tp_id;
	UINT16 cur_channel;
    UINT8  cur_ca_mode;
	UINT8  change_enable = TRUE;

	cur_channel = sys_data_get_cur_group_cur_mode_channel();
	get_prog_at(cur_channel, &p_node);
	cur_tp_id = p_node.tp_id;
    cur_ca_mode = p_node.ca_mode;
	
	if (api_pvr_is_recording())
	{
		get_prog_at(chan_idx, &p_node);
		if(p_node.tp_id == cur_tp_id)
		{
			change_enable = TRUE;

			if (cur_ca_mode && (sys_data_get_scramble_record_mode() == 1) &&
				api_pvr_is_record_active() && api_pvr_is_recording_cur_prog())
			{
				change_enable = FALSE;
				if (chan_idx == cur_channel)
					return;
			}
		}
		else
		{
			change_enable = FALSE;
		}
	}
	
	if (!change_enable)
	{
		UINT8 back_saved;
		win_compopup_init(WIN_POPUP_TYPE_OK); 					   
		win_compopup_set_frame(MSG_POPUP_LAYER_L, MSG_POPUP_LAYER_T, MSG_POPUP_LAYER_W, MSG_POPUP_LAYER_H);
		win_compopup_set_msg("Please stop record, then change channel!",NULL,0);
		win_compopup_open_ext(&back_saved);
		return;
	}
#endif

	UINT8 i;
	UINT8 back_saved;
	
	SYSTEM_DATA *sys_data = sys_data_get();//for fix bug30192
	for(i=0;i<MAX_TIMER_NUM;i++)
	{
		if((sys_data->timer_set.TimerContent[i].wakeup_state == TIMER_STATE_RUNING) 
			&& (sys_data->timer_set.TimerContent[i].wakeup_duration_time > 0)
			&& (sys_data->timer_set.TimerContent[i].timer_service == TIMER_SERVICE_CHANNEL))
			sys_data->timer_set.TimerContent[i].wakeup_duration_time = 0;
	}
#ifdef MULTIFEED_SUPPORT
	/* 
	 * when change to the channel has multifeed, switch to the master feed.
	 * add for customer GMI.
	 * but the spec required that when change to the channel has multifeed,
	 * STB should play the last playing subfeed before user leaving that channel
	 */
	/*
	P_NODE p_node2;
	get_prog_at(chan_idx, &p_node2);
	if(multifeed_have_feed(p_node2.prog_id))
	{
		multifeed_change_feed( chan_idx, 0 );
	}
	*/
#endif
   // #ifdef SUPPORT_CAS9
   #if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)
    	/*clean msg*/
    	clean_mmi_msg(1, TRUE);
    	clean_mmi_msg(3, TRUE);
    	clean_mmi_msg(4, TRUE);
    	clean_mmi_msg(6, TRUE);
    	if(get_mmi_showed()==1||get_mmi_showed()==6)
    	{
    		//win_mmipopup_close(1);
    			#if defined(SUPPORT_CAS7)//SUPPORT_CAS7 alone
    			win_mmipopup_close(1);
    			#else
			win_pop_msg_close(1);
			#endif
    		//win_fingerpop_close();
    	}
    	if(get_mmi_showed()!=5)
    		set_mmi_showed(10);
    #endif

	#if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)
		Clear_Switch_Back_Channel();
	#endif


	
	api_play_channel(chan_idx, TRUE, TRUE,FALSE);

#ifdef SAT2IP_CLIENT_SUPPORT		
	if (api_cur_prog_is_sat2ip())
	{
	//	win_satip_set_prog_selected(chan_idx);
       	win_satip_play_channel(chan_idx, FALSE, 0, 0);
	}
#endif

}

